package javaz.liquibase.csv;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import liquibase.util.csv.CSVReader;

public class ImportCSV {
	
	private static final String CSV_FILE = "/resources/liquibase/ImportData.csv";
	
	public static void main(String[] args) {
		ImportCSV.readDataFromFile(System.getProperty("user.dir") + CSV_FILE);
	}

	@SuppressWarnings("rawtypes")
	public static void readDataFromFile(String path) {
		try {
			List list = readFile(path);

			for (int index = 0; index < list.size(); index++) {
				String[] array = (String[]) list.get(index);
				for (int colIndex = 0; colIndex < array.length; colIndex++) {
					System.out.print(" - " + array[colIndex]);
				}
				System.out.println();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	/**
	 * NOTES !!
	 * @param path String
	 * @return List
	 */
	@SuppressWarnings("rawtypes")
	public static List readFile(String path) {
		try {
			CSVReader reader = new CSVReader(new FileReader(path), ';', '\"');
			return reader.readAll();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
